//
//  OAMyInfoVC.m
//  OA项目
//
//  Created by innofive on 2018/4/25.
//  Copyright © 2018年 inno. All rights reserved.
//

#import "OAMyInfoVC.h"
#import "UIBarButtonItem+Extension.h"
#import "OAMyInfoCell.h"
#import "OAGongHaoVC.h"
#import "MCIconManage.h"
#import "UIActionSheet+NTESBlock.h"

@interface OAMyInfoVC ()

@end

@implementation OAMyInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];

    UIBarButtonItem *rightItem =[UIBarButtonItem OnCreateBarBtnItemName:@"保存" BarBtnstyle:(RightBarBtnItemStyle) Btntag:10 target:self action:@selector(onRightButton:)];
    self.navigationItem.rightBarButtonItem = rightItem;
    

    NSArray *arr = @[
                     @[@{@"title":@"头像",@"imageName":@"touxiang",@"title1":@""}],
               
                     @[@{@"title":@"姓名",@"imageName":@"",@"title1":@"刘华华"},
                       @{@"title":@"性别",@"imageName":@"",@"title1":@"男"},
                       @{@"title":@"电话",@"imageName":@"",@"title1":@"13000114533"}
                       ],
                  
                     @[@{@"title":@"部门职位",@"imageName":@"",@"title1":@"综合办 主任"},
                       @{@"title":@"工号",@"imageName":@"",@"title1":@"1005687464"},
                       @{@"title":@"邮箱",@"imageName":@"",@"title1":@"130001145"},
                       @{@"title":@"地址",@"imageName":@"",@"title1":@"广东省广州市白云区M创意园A栋401C"}
                       ],
                     @[@{@"title":@"生日",@"imageName":@"",@"title1":@"2017-01-29"},
                       @{@"title":@"籍贯",@"imageName":@"",@"title1":@"湖南"},
                       @{@"title":@"民族",@"imageName":@"",@"title1":@"汉"},
                       @{@"title":@"身份证号",@"imageName":@"",@"title1":@"42900446*********4165"},
                       @{@"title":@"婚姻状况",@"imageName":@"",@"title1":@"未婚"},
                       @{@"title":@"子女",@"imageName":@"",@"title1":@"无"},
                       @{@"title":@"家庭住址",@"imageName":@"",@"title1":@"湖南省实施市谁谁谁都爱上"},
                       @{@"title":@"紧急联系人",@"imageName":@"",@"title1":@"吉吉"},
                       @{@"title":@"毕业日期",@"imageName":@"",@"title1":@"2015-07-01"},
                       @{@"title":@"入职日期",@"imageName":@"",@"title1":@"2015-07-01"},
                       ],
                      ];
  
    [self.dataArr addObjectsFromArray:arr];
    
    
}

-(void)onLoadViewByWillAppear:(UITableView *)view
{
    view.backgroundColor = hexCOLOR(@"F1F1F1");

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return self.dataArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [self.dataArr[section]count];
}


-(MCCellInfo *)tableView:(UITableView *)tableView cellForIndexPath:(NSIndexPath *)indexPath IsHeight:(BOOL)isheight
{
    if (indexPath.section==0) {
        return [MCCellInfo configForCellId:cell Class:[OAMyInfo1Cell class] Height:kFitH(50) TableView:tableView];
    }
  
    return [MCCellInfo configForCellId:cell2 Class:[OAMyInfo2Cell class] Height:kFitH(50) TableView:tableView CellStyle:(UITableViewCellStyleValue1)];
 
}

-(MCHFViewInfo *)tableView:(UITableView *)tableView HeaderInSection:(NSInteger)section isBiao:(BOOL)isBiao
{
    if (section==1||section==2) {
        return [MCHFViewInfo configForViewId:header Class:[BaseTableViewHeaderFooterView class] Height:kFitH(10) TableView:tableView IsBian:NO];
    }else if (section==3)
    {
        return [MCHFViewInfo configForViewId:header1 Class:[OAMyInfoHeaderView class] Height:kFitH(40) TableView:tableView IsBian:NO];
    }
    return nil;
}

-(id)modelForIndexPath:(NSIndexPath *)indexPath
{
    return self.dataArr[indexPath.section][indexPath.row];
}
-(id)headerViewModelForSection:(NSInteger)section
{
    if (section==3) {
        return @"隐私信息(只有管理员才能查看)";
    }
    return nil;
}

#pragma mark - 点击事件
-(void)onRightButton:(UIButton *)button
{
    
}
-(void)onSetSubviewSELForCell:(BaseTableViewCell *)cell forTableView:(UITableView *)tableView forIndexPath:(NSIndexPath *)indexPath
{
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section==0)
    {
        [MCIconManage onImageForVC:self canEditImage:YES isSheetView:NO ReturnImage:^(MCIconManage *iconManage, UIImage *image) {
            
        } ReturnError:^(NSString *error) {
            
        }Titles:@[@"拍照",@"从相册选择"]];
        
    }
    else if (indexPath.section==1) {
        
        if (indexPath.row==0) {//姓名
            [self openVCForType:openTypeName];
        }
        else if (indexPath.row==2) {//电话
            [self openVCForType:openTypePhone];
        }
        else//性别
        {
            [self titles:@[@"男",@"女"] Tag:1];
            
        }
    }else if (indexPath.section==2)
    {
        if (indexPath.row==1) {//工号
            [self openVCForType:openTypeGongHao];
        }
        else if (indexPath.row==2) {//邮箱
            [self openVCForType:openTypeEmall];
        }
        else if (indexPath.row==3) {//地址
            [self openVCForType:openTypeAddress];
        }
        else//部门
        {
            [self openVCForType:openTypeZhiWei];
        }
    }else if(indexPath.section==3)
    {
        if (indexPath.row==1) {//籍贯
            [self openVCForType:openTypeJiGuan];
        }
        else if (indexPath.row==3) {//身份
            [self openVCForType:openTypeShenZheng];
        }
        else if (indexPath.row==4) {//已婚/未婚
            [self titles:@[@"未婚",@"已婚"] Tag:2];
        }
        else if (indexPath.row==5) {//有/无
            [self titles:@[@"有",@"无"] Tag:3];
        }
        else if (indexPath.row==6) {//家庭地址
            [self openVCForType:openTypeJiaAddress];
        }
        else if (indexPath.row==7) {//紧急联系人
            [self openVCForType:openTypejinJi];
        }
        
        
        
    }
    
}

-(void)openVCForType:(openType)type
{
    NSString *title;
    NSArray *arr;
    switch (type) {
        case openTypeGongHao:
        {
            title = @"工号";
            arr = @[@{@"title":@"输入工号"}];
        }
            break;
        case openTypePhone:
        {
            title = @"联系方式";
            arr = @[@{@"title":@"输入联系方式"}];
        }
            break;
        case openTypeJiGuan:
        {
            title = @"籍贯";
            arr = @[@{@"title":@"输入籍贯"}];
        }
            break;
        case openTypeShenZheng:
        {
            title = @"身份证";
            arr = @[@{@"title":@"输入身份证"}];
        }
            break;
        case openTypeEmall:
        {
            title = @"邮箱";
            arr = @[@{@"title":@"输入邮箱"}];
        }
            break;
        case openTypeName:
        {
            title = @"姓名";
            arr = @[@{@"title":@"输入姓名"}];
        }
            break;
        case openTypeAddress:
        {
            title = @"地址";
            arr = @[@{@"title":@"输入地址"}];
        }
            break;
        case openTypeJiaAddress:
        {
            title = @"家庭地址";
            arr = @[@{@"title":@"输入家庭地址"}];
        }
            break;
        case openTypeZhiWei:
        {
            title = @"部门职位";
            arr = @[@{@"title":@"部门",@"title1":@""},
                    @{@"title":@"职位",@"title1":@"输入职位"}];
        }
            break;
        case openTypejinJi:
        {
            title = @"紧急联系人";
            arr = @[@{@"title":@"姓名",@"title1":@"输入联系人名称"},
                    @{@"title":@"手机",@"title1":@"输入联系人手机号"}];
        }
            break;
            
    }
    

    OAGongHaoVC *vc = [[OAGongHaoVC alloc]initWithStyle:(UITableViewStyleGrouped)];
    vc.title = title;
    vc.type = type;
    vc.datas = arr;
    [self pushToVC:vc];
}


-(void)titles:(NSArray *)titles Tag:(NSInteger)tag
{
    UIActionSheet *sheetView = [UIActionSheet onCreatWithTitle:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:titles];
    [sheetView showInView:self.view completionHandler:^(NSInteger index) {
        if (index!=0) {
            if (index==1) {
                
            }
            else if (index==2)
            {
                
            }
        }
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
